package com.fly.controller;

import com.fly.bean.DamageRecord;
import com.fly.service.FixRecordStatisticsService;
import com.fly.util.Msg;
import com.fly.util.Page;
import com.fly.vo.TaskPageFind_WH;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class FixRecordStatisticsController {

    @Resource
    private FixRecordStatisticsService fixRecordStatisticsService;

//    消缺记录统计
    @RequestMapping("/selectFixRecord")
    @ResponseBody
    public Msg selectFixRecord(Page page) {

        List<DamageRecord> list = fixRecordStatisticsService.selectFixRecord(page);

        int count = fixRecordStatisticsService.selectFixRecordCount();

        return Msg.success().add("count", count).add("fixRecord", list);
    }

//    消缺记录统计通过条件搜索
    @RequestMapping("/selectFixRecordByFind")
    @ResponseBody
    public Msg selectFixRecordByFind(TaskPageFind_WH taskPageFind_wh) {

        if (taskPageFind_wh.getCircuitryNo() == "") {
            taskPageFind_wh.setCircuitryNo(null);
        } else {
            taskPageFind_wh.setCircuitryNo("%" + taskPageFind_wh.getCircuitryNo() + "%");
        }

        if (taskPageFind_wh.getTaskNo() == "") {
            taskPageFind_wh.setTaskNo(null);
        } else {
            taskPageFind_wh.setTaskNo("%" + taskPageFind_wh.getTaskNo() + "%");
        }

        if (taskPageFind_wh.getStartDate() == "") {
            taskPageFind_wh.setStartDate(null);
        }

        if (taskPageFind_wh.getEndDate() == "") {
            taskPageFind_wh.setEndDate(null);
        }

        int count = fixRecordStatisticsService.selectFixRecordCountByFind(taskPageFind_wh);

        List<DamageRecord> list = fixRecordStatisticsService.selectFixRecordByFind(taskPageFind_wh);

        return Msg.success().add("count", count).add("fixRecord", list);
    }


}
